// async await
function run(fn) {
    const gen = fn();
    function _next(data) {
        const { value, done } = gen.next(data);
        if (done) return value;
        if (value.then) {
            value.then(data => _next(data))
        } else {
            _next(value)
        }
    }
    _next()
}

// 样例
function sleep(duration) {
    return new Promise((resolve, reject) => {
        setTimeout(() => resolve(`sleep ${duration}`), duration)
    })
}

function * work() {
    const ret = yield sleep(3000);
    console.log(ret)
    const ret1 = yield sleep(1000);
    console.log(ret1)
}

run(work)